#ifndef XML_PARSER_HEADER
#define XML_PARSER_HEADER

#include <string>
#include <vector>
#include <utility>
#include <queue>

enum PARSE_TYPE 
{ 
	OPEN,
	CLOSE,
	TEXT
};

struct ParseEle {

	ParseEle() : needClose(true) {}

	PARSE_TYPE pt;

    std::vector< std::pair<std::string, std::string> > attrs;
    
	std::string txt;

	bool needClose;
};

//This class represents the XML parser.  It currently performs two stages:
//1. Character parsing from XML source
//2. XML Validation and building of the tree.
//
//Errors may be generated from the above commands and parsing should fail altogether if any errors
//are found in either stage.

class xml_parser
{
public:

	// Parses the input file given the XML string (should be read in from file first).
	void parse( const std::string & str );

	std::queue<ParseEle> & get_token_queue();

private:

	// Private helper methods 

	//Parses the syntax of the XML file
	int parse_syntax( const std::string & str );

	//Parses a single tag
	int parse_tag( const std::string & tag, ParseEle & pel );
    
    int parse_attr( const std::string & tag, ParseEle & pel );
    
    int get_next_attr( const std::string & tag, int & pos, ParseEle & pel );  

	int check_attr( std::pair<std::string, std::string> & inAttr );

	//remove leading and trailing whitespace...but leaves whitespace in middle of text.
	void rltw( std::string & inout );

	//Validates the XML file and creates the DOM tree.
	int validate();

	std::queue<ParseEle> m_elequeue;
};


#endif